﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.BusinessLogicLayer;
public partial class CommentManagement_CommentList : AdminUserBase
{
    VideoCommentModule vm = new VideoCommentModule();
    string sqlwhere = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData("");
            BindTrainClassData();
        }
    }
    public void BindData(string wheresql)
    {
          DataSet ds = new DataSet();
          ds= vm.GetCommentAndOtherInfoList(wheresql, this.SchoolID);
          Repeater1.DataSource = getPage(ds);
          Repeater1.DataBind();
    }
    public void BindTrainClassData()
    {
        int id = this.CurrentUser.SchoolID;
        TrainClassModule tcm = new TrainClassModule();
        DataSet ds = tcm.GetTrainclassListByWhere(id,"");
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            DataRow dr = null;
            ddlTrainClass.Items.Clear();
            ddlTrainClass.Items.Add(new ListItem("全部", "0"));
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dr = ds.Tables[0].Rows[i];
                ddlTrainClass.Items.Add(new ListItem(dr["VTC_name"].ToString(), dr["ID"].ToString()));
            }

        }
    }
    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
    protected void pager_PageChanged(object sender, EventArgs e)
    {
        BindData(sqlwhere);
       
    }
    //protected void BtCheckByTime_Click(object sender, EventArgs e)
    //{
    //    if (txtBeginDate.Text == "" || txtendDate.Text == "")
    //    { sqlwhere = ""; }
    //    else
    //    {
    //        DateTime beginDate = Convert.ToDateTime(this.txtBeginDate.Text.Trim().ToString());
    //        DateTime endDate = Convert.ToDateTime(this.txtendDate.Text.Trim().ToString());

    //        if (ddlCheckDateName.SelectedValue == "1")
    //        {
    //            sqlwhere = " and VCL_startDate between '" + beginDate + "' and '" + endDate + "'";
    //        }
    //        else
    //        {
    //            DateTime beginDateTime = Convert.ToDateTime(this.txtBeginDate.Text.Trim().ToString()+" 00:00:00");
    //            DateTime endDateTime = Convert.ToDateTime(this.txtendDate.Text.Trim().ToString()+" 23:59:59");
    //            sqlwhere = "  and CreatedTime between '" + beginDateTime + "' and '" + endDateTime + "'";
    //        }
    //    }
    //    BindData(sqlwhere);
    //}
    protected void btnCheckByTrainClass_Click(object sender, EventArgs e)
    {
       
        int trainclassid = Convert.ToInt32(ddlTrainClass.SelectedValue.ToString());
      
        if (txtBeginDate.Text == "" || txtendDate.Text == "")
        {
            if (ddlTrainClass.SelectedValue == "0")
            {
                sqlwhere = "";
            }
            else
            { sqlwhere = " and cl.trainClassID=" + trainclassid.ToString(); }
        }
        else
        {
            DateTime beginDateTime = DateTime.Now;
            DateTime endDateTime = DateTime.Now;
            if (ddlCheckDateName.SelectedValue == "1")
            {
                beginDateTime = Convert.ToDateTime(this.txtBeginDate.Text.Trim());
                endDateTime = Convert.ToDateTime(this.txtendDate.Text.Trim());
            }
            else
            {
                beginDateTime = Convert.ToDateTime(this.txtBeginDate.Text.Trim() + " 00:00:00");
                endDateTime = Convert.ToDateTime(this.txtendDate.Text.Trim() + " 23:59:59");
            }
            if (ddlTrainClass.SelectedValue == "0")
            {
                if (ddlCheckDateName.SelectedValue == "1")
                {
                    sqlwhere = " and VCL_startDate between '" + beginDateTime + "' and '" + endDateTime + "'";
                }
                else
                {
                  
                    sqlwhere = "  and CreatedTime between '" + beginDateTime + "' and '" + endDateTime + "'";
                }
            }
            else
            {

                if (ddlCheckDateName.SelectedValue == "1")
                {
                    sqlwhere = " and cl.trainClassID=" + trainclassid.ToString()+ " and VCL_startDate between '" + beginDateTime + "' and '" + endDateTime + "'";
                }
                else
                {

                    sqlwhere =  " and cl.trainClassID=" + trainclassid.ToString()+"  and CreatedTime between '" + beginDateTime + "' and '" + endDateTime + "'";
                }
            }
        }
      
        BindData(sqlwhere);
    }
    protected void btnDelete_Click(object sender, CommandEventArgs e)
    {

        int id = int.Parse(e.CommandArgument.ToString());
        int result = vm.DeleteComment(id);
        if (result > 0)
        { Response.Redirect("CommentList.aspx"); }
        else { PageHelper.AlterMsg("删除失败，请稍候再试！"); }

    }
}
